/*
 * Copyright (C) 2013 Daniel Treffenstädt <daniel@treffenstaedt.de>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 * 02110-1301  USA
 */

#include "OGradient.h"

O_START_NAMESPACE

Gradient::Gradient()
{
	m_start		= Position();
	m_direction	= Vector2D();
}

Gradient::Gradient(Position s, Vector2D d)
{
	m_start		= s;
	m_direction	= d;
}

Gradient::~Gradient()
{
	for (int i = 0; i < m_stops.length(); i++)
	{
		delete m_stops[i];
	}

	m_stops.clear();
}

void Gradient::addStop(GradientStop *s)
{
	m_stops.append(s);
}

void Gradient::addStop(Color c, double p)
{
	m_stops.append(new GradientStop(c, p));
}

int Gradient::stops()
{
	return m_stops.length();
}

GradientStop* Gradient::getStop(int index)
{
	if (index >= stops() || index < 0)
	{
		return 0;
	}
	return m_stops[index];
}

Position Gradient::start()
{
	return m_start;
}

Vector2D Gradient::direction()
{
	return m_direction;
}

void Gradient::operator =(Gradient g)
{
	m_start		= g.m_start;
	m_direction	= g.m_direction;

	for (int i = 0; i < g.stops(); i++)
	{
		addStop(g.getStop(i));
	}
}

O_END_NAMESPACE
